package com.own.center;

import java.util.List;

import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn;
import org.apache.wicket.markup.repeater.Item;
import org.apache.wicket.model.IModel;

import com.own.core.html.panel.OwnPanel;
import com.own.core.html.panel.link.OwnAjaxLinkPanel;
import com.own.core.html.table.OwnAbstractColumn;
import com.own.core.object.Dao;
import com.own.core.operation.Controller;
import com.own.core.operation.DbOperation;
import com.own.util.listener.OwnListener;

public class HoleController extends Controller {

	@Override
	public void beforeRenderAdd() {

	}

	@Override
	public void afterRenderAdd(Dao dao) {
		// create seat
		int counter = 1;
		Hole hole = (Hole) dao;
		for (int r = 0; r < hole.getRow(); r++) {
			for (int c = 0; c < hole.getColume(); c++) {
				Seat seat = new Seat(hole.getSeatPrefixName() + counter++, hole);
				DbOperation.getME().saveOrUpdate(seat);

			}
		}

	}

	@Override
	public void beforeRenderEdit() {

	}

	@Override
	public void afterRenderEdit(Dao dao) {

	}

	@Override
	public void beforeRenderList() {

	}

	@Override
	public void afterRenderList(List<IColumn> columns, final OwnPanel panel) {

		columns.add(new OwnAbstractColumn("Seats") {
			@Override
			public void populateItem(Item item, String componentId,
					IModel rowModel) {

				OwnAjaxLinkPanel ownAjaxLinkPanel = new OwnAjaxLinkPanel(
						componentId, getDisplayModel());

				ownAjaxLinkPanel.addOwnListener(new OwnListener(rowModel) {
					public void execute(AjaxRequestTarget target) {
						
						panel.getModalWindow().setContent(
								new HoleSeatGraph("content", ((Hole) model
										.getObject())));
						panel.getModalWindow().show(target);

					}
				});

				item.add(ownAjaxLinkPanel);
			}
		});

	}

	@Override
	public void beforeRenderDelete() {

	}

	@Override
	public void afterRenderDelete() {

	}

	@Override
	public void beforeRender() {

	}

	@Override
	public void afterRender() {

	}

	@Override
	public void Undo() {

	}

	@Override
	public void Redo() {

	}

	@Override
	public void drawAddField() {

	}

	@Override
	public void drawEditField() {

	}

	@Override
	public void drawListField() {

	}

}
